package com.example.test.controller;


import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.TypeReference;
import com.example.test.bean.BaseOrders;
import com.example.test.bean.DTO.input.OrderInputDTO;
import com.example.test.bean.DTO.output.OrderOutputDTO;
import com.example.test.bean.OrderGoods;
import com.example.test.common.model.PageModel;
import com.example.test.common.model.R;
import com.example.test.common.token.LoginToken;
import com.example.test.service.BaseOrdersService;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.List;

/**
 * <p>
 * 基础订单表 前端控制器
 * </p>
 *
 * @author dz
 * @since 2022-04-10
 */
@CrossOrigin
@RestController
@RequestMapping("/base-orders")
public class BaseOrdersController {

    @Resource
    private BaseOrdersService baseOrdersService;

    @LoginToken
    @ApiOperation(value = "根据keyword分页查询")
    @PostMapping("/getByKeyword")
    public R usersList(@RequestBody JSONObject jsonParam) {
        System.out.println(jsonParam.toJSONString());
        String keyword = jsonParam.getString("keyword");
        Long size = Long.valueOf(jsonParam.getString("size"));
        Long current = Long.valueOf(jsonParam.getString("current"));
        PageModel pageModel = new PageModel();
        pageModel.setCurrent(current);
        pageModel.setSize(size);
        return baseOrdersService.getOrderByKeyword(keyword,pageModel);
    }
    @LoginToken
    @ApiOperation(value = "根据id分页查询")
    @PostMapping("/getOrder")
    public R listById(@RequestBody JSONObject jsonParam) {
        Long orderId = Long.valueOf(jsonParam.getString("orderId"));
        return baseOrdersService.getOrder(orderId);
    }
    @LoginToken
    @ApiOperation(value = "插入订单")
    @PostMapping("/add")
    public R insert( @RequestBody OrderOutputDTO orderOutputDTO) {

        return baseOrdersService.addOrder(orderOutputDTO);
    }
    @LoginToken
    @ApiOperation(value = "更新订单")
    @PostMapping("/update")
    public R updateOrder(@RequestBody  OrderInputDTO orderInputDTO) {
//        jsonParam.getString("")
        return baseOrdersService.updateOrder(orderInputDTO);
    }
    @LoginToken
    @ApiOperation(value = "完成订单")
    @PostMapping("/finish")
    public R finishOrder(@RequestBody JSONObject jsonParam) {
        Long orderId = Long.valueOf(jsonParam.getString("orderId"));
        return baseOrdersService.finishOrder(orderId);
    }
    @LoginToken
    @ApiOperation(value = "删除订单")
    @PostMapping("/delete")
    public R deleteOrder(@RequestBody JSONObject jsonParam) {
        Long orderId = Long.valueOf(jsonParam.getString("orderId"));
        return baseOrdersService.deleteOrder(orderId);
    }
    @LoginToken
    @ApiOperation(value = "删除订单")
    @GetMapping("/create")
    public R create() {
        return baseOrdersService.createAll();
    }
}

